<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.SQLException" %><%--
  Created by IntelliJ IDEA.
  User: 自由如风
  Date: 2018/3/26
  Time: 18:59
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>更新用户</title>
    <style>

        form {
            font-size: 8px;
        }

        a {
            font-size: 8px;
        }

        input {
            height: 8px;
            width: 30px;
            font-size: 5px;
        }

        #input {
            font-size: 1px;
        }

    </style>
</head>
<body>
<a href="userList.jsp">返回列表</a>

<form>
    <input type="text" name="id" value="${param.idvalue}" hidden></br>
    用户:<input type="text" name="username" value="${param.namevalue}"></br>
    密码:<input type="text" name="password" value="${param.passvalue}"></br>
    <input type="submit" id="input" value="更新">
</form>

<%
    String s = request.getParameter("id");
    String name = request.getParameter("username");
    String pass = requeest.getParameter("password");

    Connection connection = null;
    Statement statement = null;

    try {
        Class.forName("com.mysql.cj.jdbc.Driver");

        connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/sctu_javaweb_2018?serverTimezone = UTC && characterEncoding = UTF-8", "root", "193749");
        statement = connection.createStatement();
        statement.executeUpdate("UPDATE t_users SET username = '" + name + "',password = '" + pass + "' WHERE id = '" + s + "';");
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } finally {
        try {
            connection.close();
            statement.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
%>

</body>
</html>
